<?php
namespace Admin\Controller;
use Think\Controller;
class ActivityController extends BaseController {
   public function activitylist(){
        $videosModel=M('activity'); //实例化模型对象 user 表名
		$videos=$videosModel->order('activity_id desc')->select(); //查询
		$this->videos=$videos; //volist name
		// dump ($users); 
		$this->display();
}
 public function delactivity(){
        // dump($_GET);
        $videoModel=M('activity');
        $vid=$_GET['vid'];
        $res=$videoModel->where("activity_id=$vid")->find();
        //var_dump($res);
        if ($videoModel->where("activity_id=$vid")->delete()) {
        	$this->success('删除成功');
        }else{
        	$this->error('删除失败');
        }

    }
    public function addvideo(){   
  
        $videos = D('activity'); 
        $data['activity_name']=I('post.activityname');
        $data['activity_intro']=I('post.activityintro');
        $data['activity_tel']=I('post.activitytel');
        $data['activity_address']=I('post.activityaddress');
        $data['activity_time']=I('post.activitytime');
        $data['activity_sprice']=I('post.activitysprice');
        $data['activity_aprice']=I('post.activityaprice');
        $data['activity_name_peo']=I('post.activitypeo');
        $data['activity_peo_tel']=I('post.activitypeotel');
        $data['activity_date']=date('Y-m-d H:i:s');
         if(false!==$videos->add($data)){
             $this->success('成功','activitylist');
         }else{
            $this->error('失败');
         }
        }//register end
     public function activityedit(){
      
        $videos = D('activity'); 
        $vid=I('post.id');
        $data['activity_name']=I('post.activityname');
        $data['activity_intro']=I('post.activityintro');
        $data['activity_tel']=I('post.activitytel');
        $data['activity_address']=I('post.activityaddress');
        $data['activity_time']=I('post.activitytime');
        $data['activity_sprice']=I('post.activitysprice');
        $data['activity_aprice']=I('post.activityaprice');
        $data['activity_name_peo']=I('post.activitypeo');
        $data['activity_peo_tel']=I('post.activitypeotel');
        $data['activity_date']=date('Y-m-d H:i:s');
        if(false !== $videos->where("activity_id=$vid")->save($data)){
            $this->success('成功','activitylist');
         }else{
            $this->error('失败');
         }

        }//register end
    public function editactivity(){    
            $videos = M('activity'); 
            $vid=$_GET['id'];
            $res=$videos->where("activity_id=$vid")->find();
            $this->videos=$res;
         
        $this->display();
        }



    public function MyUpload(){
    $upload = new \Think\Upload();// 实例化上传类
    $upload->maxSize   =     3145728 ;// 设置附件上传大小
    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    $upload->rootPath  =     './Public/Uploads/videophoto/'; // 设置附件上传根目录
    $upload->autoSub   = false;//关闭子目录，默认ture
    //$info=$upload->uploadOne($_FILES['file']);  //上传文件

    //$upload->savePath  =     ''; // 设置附件上传（子）目录
    $upload->savename = 'time';

    $info   =   $upload->upload();  // 上传文件 
    //$dump(info);
    if(!$info) {        $this->error($upload->getError());    }
    else{return $info;}
    
    // else{        $this->success('上传成功！');    }  


    } //MyUpload end

}